# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=pyjwt
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
provides=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
conflicts=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
replaces=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
pkgver=1.7.1
pkgrel=3
pkgdesc='JSON Web Token implementation in Python (mingw-w64)'
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url='https://github.com/jpadilla/pyjwt'
license=('MIT')
depends=("${MINGW_PACKAGE_PREFIX}-python-setuptools")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-setuptools")
checkdepends=("${MINGW_PACKAGE_PREFIX}-python-pytest-runner")
source=("${_realname}-${pkgver}.tar.gz::https://github.com/jpadilla/pyjwt/archive/${pkgver}.tar.gz")
sha256sums=('aeadd62d894ac7005beaa747c2bc077a1f1169bdb145c536cae33bf20824faa4')

prepare() {
  cd "${srcdir}"
  sed -i 's/pytest==2.7.3/pytest/;/pytest-cov/d' ${_realname}-${pkgver}/setup.py
  # do not use python-coverage
  sed -i 's/--cov-report term-missing --cov-config=.coveragerc --cov .//' ${_realname}-${pkgver}/setup.cfg

  rm -rf python-build-${CARCH} | true
  cp -r "${_realname}-${pkgver}" "python-build-${CARCH}"
}

build() {
  cd "${srcdir}/python-build-${CARCH}"
  ${MINGW_PREFIX}/bin/python setup.py build
}

package() {
  cd "${srcdir}/python-build-${CARCH}"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python setup.py install --prefix=${MINGW_PREFIX} \
    --root="${pkgdir}" --optimize=1 --skip-build
  
  install -Dm644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/LICENSE"

  for _f in "${pkgdir}${MINGW_PREFIX}"/bin/*-script.py; do
    sed -e '1 { s/^#!.*$// }' -i ${_f}
  done
}
